import React, { Component } from 'react'
import { withRouter } from "react-router-dom"
import { connect } from 'react-redux'
import { getBus } from '../../redux/actionCreator'
import { Msgget_tim, Send_tim } from '../../TIM/actiontim'
import { Toast } from 'antd-mobile'
import C2c2 from './C2c2'

class Kefu2 extends Component {
    constructor(props) {
        super(props)
        let userphone = this.props.location.search.split('=')
        let arr = this.props.user.filter((item) => {
            return item.user_phone == userphone[1].replace(' ', '')
        })
        this.state = {
            user: arr[0],
            phone: userphone[1].replace(' ','')
        }
        localStorage.getItem('sdkready')
            ? this.props.dispatch(Msgget_tim(this.state.phone))
            : setTimeout(() => {
                this.props.dispatch(Msgget_tim(this.state.phone))
                console.log('超时风险')
            }, 3000, Toast.loading('Loading...', 3))
    }

    render() {
        const { user } = this.state
        return (
            <div className='kefu'>
                <C2c2 user={user} />
            </div>
        )
    }
}
const mapStateToProps = (state) => ({
    login: state.login,
    business: state.business,
    conversation: state.conversation,
    message: state.message,
    user: state.user
})
export default withRouter(connect(mapStateToProps)(Kefu2))